/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JF_AddBeneficiario.java
 *
 * Created on 14-mar-2010, 21:52:51
 */

package cliente.presentacion.administrador.beneficiarios;

import cliente.negocio.Controlador_Gestion_Beneficiario;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import server.dominio.Beneficiario;
import server.dominio.Medico;


/**
 *
 * @author tpaxle
 */
public class JF_AddBeneficiario extends javax.swing.JFrame implements iJF_AddBeneficiario{
    private Beneficiario beneficiariomostrado;
    private Controlador_Gestion_Beneficiario C_Admin;
    private Medico medicoseleccionado;
    private int anopediatra;
    private boolean pediatraactivo= false;
    /** Creates new form JF_AddBeneficiario */
    public JF_AddBeneficiario(Controlador_Gestion_Beneficiario C_Admin) {
        initComponents();
        this.setLocation((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/4,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/6);
        this.C_Admin= C_Admin;
        iniciarmedicos(1);
        this.iniciaragnos();
        //Calculo de años para pediatra
        Calendar calendario = Calendar.getInstance();
        calendario.setTime(new Date());
        anopediatra= calendario.get(Calendar.YEAR)-14;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jLabel16 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jTextField_NIF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField_NSS = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField_med_Nif = new javax.swing.JTextField();
        jTextField_medi_Nombre = new javax.swing.JTextField();
        jTextField_medi_apellidos = new javax.swing.JTextField();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jLabel18 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jTextField_email = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jTextField_Nombre = new javax.swing.JTextField();
        jTextField_Apellido = new javax.swing.JTextField();
        jTextField_domicilio = new javax.swing.JTextField();
        jTextField_telefonofijo = new javax.swing.JTextField();
        jTextField_telmovil = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jButton_ok = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1268112229_list-add-user.png"))); // NOI18N

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos de usuario"));

        jLabel16.setText("Medico:");
        jLabel16.setBounds(10, 100, 50, 20);
        jLayeredPane2.add(jLabel16, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox4ActionPerformed(evt);
            }
        });
        jComboBox4.setBounds(70, 100, 180, 22);
        jLayeredPane2.add(jComboBox4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel19.setText("NIF:");
        jLabel19.setBounds(20, 70, 40, 16);
        jLayeredPane2.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_NIF.setBounds(70, 70, 180, 20);
        jLayeredPane2.add(jTextField_NIF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("NSS");
        jLabel2.setBounds(20, 30, 40, 16);
        jLayeredPane2.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_NSS.setBounds(70, 30, 180, 22);
        jLayeredPane2.add(jTextField_NSS, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Medico Cabecera"));

        jLabel3.setText("Nif");

        jLabel4.setText("Especialidad");

        jLabel5.setText("Nombre");

        jLabel6.setText("Apellidos");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cabecera", "Pediatría", "Urología", "Cirugía", "Neurología", "Ginecología", "Digestivo", "Oftalmología" }));
        jComboBox1.setEnabled(false);

        jTextField_med_Nif.setEditable(false);

        jTextField_medi_Nombre.setEditable(false);

        jTextField_medi_apellidos.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox1, 0, 114, Short.MAX_VALUE)
                    .addComponent(jTextField_med_Nif, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField_medi_Nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(jTextField_medi_apellidos, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_medi_Nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_med_Nif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_medi_apellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6))
                .addGap(28, 28, 28))
        );

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos personales"));

        jLabel18.setText("Nombre:");
        jLabel18.setBounds(20, 40, 70, 16);
        jLayeredPane3.add(jLabel18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setText("Apellidos:");
        jLabel20.setBounds(20, 70, 70, 16);
        jLayeredPane3.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setText("Domicilio:");
        jLabel22.setBounds(20, 100, 60, 16);
        jLayeredPane3.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setText("Telf. Fijo:");
        jLabel23.setBounds(20, 130, 70, 16);
        jLayeredPane3.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel24.setText("Telf. Movil:");
        jLabel24.setBounds(230, 130, 70, 16);
        jLayeredPane3.add(jLabel24, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_email.setBounds(100, 160, 330, 20);
        jLayeredPane3.add(jTextField_email, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel26.setText("Email:");
        jLabel26.setBounds(20, 160, 50, 16);
        jLayeredPane3.add(jLabel26, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_Nombre.setBounds(100, 40, 140, 20);
        jLayeredPane3.add(jTextField_Nombre, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_Apellido.setBounds(100, 70, 330, 20);
        jLayeredPane3.add(jTextField_Apellido, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_domicilio.setBounds(100, 100, 330, 20);
        jLayeredPane3.add(jTextField_domicilio, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_telefonofijo.setBounds(100, 130, 110, 20);
        jLayeredPane3.add(jTextField_telefonofijo, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_telmovil.setBounds(310, 130, 120, 20);
        jLayeredPane3.add(jTextField_telmovil, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel21.setText("Fecha de nacimiento:");
        jLabel21.setBounds(20, 200, 130, 20);
        jLayeredPane3.add(jLabel21, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox2.setBounds(160, 200, 70, 22);
        jLayeredPane3.add(jComboBox2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
        jComboBox3.setBounds(230, 200, 120, 22);
        jLayeredPane3.add(jComboBox3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });
        jComboBox5.setBounds(350, 200, 64, 22);
        jLayeredPane3.add(jComboBox5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton_ok.setText("Añadir");
        jButton_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_okActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(243, 243, 243)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(jLabel1)
                                .addGap(28, 28, 28)
                                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)))
                        .addGap(286, 286, 286)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 465, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_okActionPerformed
      if(camposobligatorios()){
            String mes, dia;
            if(jComboBox3.getSelectedIndex()<9){
                mes= "0"+(jComboBox3.getSelectedIndex()+1);
            }else{
                mes= ""+(jComboBox3.getSelectedIndex()+1);
            }
            if(jComboBox2.getSelectedIndex()<9){
                dia= "0"+(jComboBox2.getSelectedIndex()+1);
            }else{
                dia= ""+(jComboBox2.getSelectedIndex()+1);
            }
            String fechanacimiento= jComboBox5.getSelectedItem().toString() + "-" + mes + "-"+dia;
            String tipomedico= (String) jComboBox1.getSelectedItem();
        

           String [] informacion= {jTextField_NSS.getText(),jTextField_NIF.getText(), jTextField_Nombre.getText(), jTextField_Apellido.getText(), jTextField_domicilio.getText(), jTextField_email.getText(), jTextField_telefonofijo.getText(), jTextField_telmovil.getText(), fechanacimiento, ""+jTextField_med_Nif.getText()};
           C_Admin.nuevobeneficiario(informacion);
           
        }else{
            JOptionPane.showMessageDialog(null, "Introduzca todos los datos obligatorios", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
        }

}//GEN-LAST:event_jButton_okActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox4ActionPerformed
        this.iniciarmedico(jComboBox4.getSelectedIndex());
    }//GEN-LAST:event_jComboBox4ActionPerformed

    private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed

        if(Integer.parseInt((String) jComboBox5.getSelectedItem())>anopediatra){
            pediatraactivo= true;
            this.iniciarmedicos(2);

        }else{
            pediatraactivo= false;
            this.iniciarmedicos(1);
        }
    }//GEN-LAST:event_jComboBox5ActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_ok;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextField_Apellido;
    private javax.swing.JTextField jTextField_NIF;
    private javax.swing.JTextField jTextField_NSS;
    private javax.swing.JTextField jTextField_Nombre;
    private javax.swing.JTextField jTextField_domicilio;
    private javax.swing.JTextField jTextField_email;
    private javax.swing.JTextField jTextField_med_Nif;
    private javax.swing.JTextField jTextField_medi_Nombre;
    private javax.swing.JTextField jTextField_medi_apellidos;
    private javax.swing.JTextField jTextField_telefonofijo;
    private javax.swing.JTextField jTextField_telmovil;
    // End of variables declaration//GEN-END:variables

    private void iniciarmedicos(int tipo) {
        Medico medico;
        ArrayList<server.dominio.Medico> listamedicos;
        listamedicos= C_Admin.getListamedicos();
        String [] datos;

        datos= new String[listamedicos.size()];
        ArrayList<String> listadatos= new ArrayList<String>();
        for(int i=0; i<listamedicos.size(); i++){
            if(listamedicos.get(i).getTipo_medico()== tipo){
                listadatos.add(listamedicos.get(i).getNif() + "  " +listamedicos.get(i).getNombre() + "  " + listamedicos.get(i).getApellidos());
            }
        }

        if(listadatos.size()>0){
            jComboBox4.setModel(new DefaultComboBoxModel(listadatos.toArray()));
            jComboBox1.setSelectedIndex(listamedicos.get(0).getTipo_medico()-1);
            jTextField_med_Nif.setText(listamedicos.get(0).getNif());
            jTextField_medi_Nombre.setText(listamedicos.get(0).getNombre());
            jTextField_medi_apellidos.setText(listamedicos.get(0).getApellidos());
            jComboBox4.setSelectedIndex(0);
        }else{
            Object [] ob= {};
            jComboBox4.setModel(new DefaultComboBoxModel(ob));
            jComboBox1.setSelectedIndex(-1);
            jTextField_med_Nif.setText("");
            jTextField_medi_Nombre.setText("");
            jTextField_medi_apellidos.setText("");

        }


        }

    private void iniciarmedico(int nmedico){
        for(int i=0,j=0; i< this.C_Admin.getListamedicos().size(); i++){
            if(pediatraactivo && C_Admin.getListamedicos().get(i).getTipo_medico()==2){
                if(j== nmedico){
                    this.medicoseleccionado=C_Admin.getListamedicos().get(i);
                    break;
                }else
                    j++;
            }else{
                if(!pediatraactivo && C_Admin.getListamedicos().get(i).getTipo_medico()==1){
                    if(j==nmedico){
                        this.medicoseleccionado= C_Admin.getListamedicos().get(i);
                        break;
                    }else
                        j++;
                }
            }
        }

        jTextField_med_Nif.setText(medicoseleccionado.getNif());
        jTextField_medi_Nombre.setText(medicoseleccionado.getNombre());
        jTextField_medi_apellidos.setText(medicoseleccionado.getApellidos());
        jComboBox1.setSelectedIndex(medicoseleccionado.getTipo_medico()-1);
    }

    public void mostrar(boolean b) {
        this.setVisible(true);
    }
    private boolean camposobligatorios() {
        boolean solucion= true;
        solucion= solucion && jTextField_NIF.getText().length()>0 && jTextField_Nombre.getText().length()>0;
        solucion= solucion && jTextField_Apellido.getText().length()>0 && jTextField_telefonofijo.getText().length()>0;
        solucion= solucion && jTextField_NSS.getText().length()>0 && jTextField_domicilio.getText().length()>0;
        solucion= solucion && jComboBox4.getSelectedIndex()!=-1;
        return solucion;

    }
    private void iniciaragnos() {
        String [] datos= new String[160];
        for(int i=0; i<160; i++){
            datos[i]= ""+ (1900 +i);
        }
        jComboBox5.setModel(new DefaultComboBoxModel(datos));
    }
    public void error(int opcion) {
        switch(opcion){
            case 1:
                JOptionPane.showMessageDialog(null, "El medico es incorrecto, reinicie la aplicacion", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
                C_Admin.getC_admin().getAdmin_Control().log("Error al obtener medico");
                break;
            case 2:
                JOptionPane.showMessageDialog(null, "DNI o NSS repetido", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
                C_Admin.getC_admin().getAdmin_Control().log("DNI o NSS repetido");
                break;
        }
    }

    public void cerrar() {
        this.dispose();
    }

    public void mostrar(String string) {
        JOptionPane.showMessageDialog(null, string, "Advertencia", JOptionPane.INFORMATION_MESSAGE);
    }

    public void introducirdninss(String dni, String nss) {
        jTextField_NIF.setText(dni);
        jTextField_NSS.setText(nss);
    }
  
}
